
<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
      <three-title :title="{name:'资料打印'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFiveShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">打印</p>
            <div class="analyItemCon">
                <a :href="href" class="cBlue" :target="target" @click="printing()">打印</a>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="提交" v-if="buttonIsShow" @click="submitButton()">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { printData, PostJump } from '../../../../Resources/Api/scene'
import { mapGetters, mapMutations } from 'vuex'
export default {
    props: ['type'],
    data () {
        return {
            buttonIsShow: false, // 是否显示按钮
            href: '#',
            target: '_self'
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo', 'twoToThreeInfo'])
    },
    created () {
        this.buttonType()
        this.printData()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                const userLevel = this.userInfo.as_level
                if (userLevel.length > 0) {
                    userLevel.forEach(ele => {
                        if (Number(ele) === 82 || Number(ele) === 83) {
                            if (this.twoToThreeInfo.status === this.type) {
                                this.buttonIsShow = true
                            } else {
                                this.buttonIsShow = false
                            }
                        } else if (Number(ele) === 47) {
                            if (Number(this.userInfo.as_cardNo) === Number(this.leftInfo.supervisor_userno)) {
                                if (this.twoToThreeInfo.status === this.type) {
                                    this.buttonIsShow = true
                                } else {
                                    this.buttonIsShow = false
                                }
                            } else {
                                this.buttonIsShow = false
                            }
                        } else {
                            this.buttonIsShow = false
                        }
                    })
                } else {
                    this.buttonIsShow = false
                }
            }
        },
        // a 标签点击提示
        printing () {
            if (this.href === '#') {
                this.$message({
                    type: 'info',
                    message: '请稍后重试'
                })
            }
        },
        // 获取打印数据
        printData () {
            let parm = {
                dataType: 86,
                orderNo: this.leftInfo.orderno,
                createUserName: this.userInfo.as_fullName
            }
            // 获取模板数据
            printData(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    let url = results.data.Body
                    if (url !== null) {
                        this.href = url
                        this.target = '_blank'
                    }
                } else {
                    this.$message({
                        type: 'info',
                        message: '请稍后重试'
                    })
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 提交
        submitButton () {
            let parm = {
                orderCode: this.$route.query.code,
                // createUserNo: this.getCookie('u_kahao'),
                // createUserName: this.getCookie('xinming')
                createUserNo: this.userInfo.as_cardNo,
                createUserName: this.userInfo.as_fullName
            }
            // const dataJson = JSON.stringify(parm)
            // 阶段接口
            PostJump(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.setUpDatePlate()
                    this.$parent.$parent.clickFiveShow()
                }
            }).catch(error => {
                console.log(error)
            })
        }
    },
    watch: {
    }
}
</script>
<style lang="">
    .dataTitle {
        position: absolute;
        right: 10px;
        bottom: 5px;
    }
    .w100 {
        width:100px;
    }
</style>
